package com.demo.algorithm;

/**
 * Created by lmn on 2018/7/26.
 * 排序算法
 */
public class SortingAlgorithm {

    public static void main(String[] args) {
        BubbleSort();
    }

    public static void BubbleSort(){
        int[] nums = new int[]{1,5,8,7,3,6,2,9};
        int temp = 0;
        for(int i=0;i<nums.length-1;i++){
            if(i<=nums.length-2){
                if(nums[i] > nums[i+1]){
                    temp = nums[i];
                    nums[i] = nums[i+1];
                    nums[i+1] = temp;
                }
            }
        }
        for(int i=0;i<nums.length-1;i++){
            System.out.println(nums[i]);
        }
    }
}
